import Vue from 'vue'
import Router from 'vue-router'
import router from './router'
import store from './store'
// import { Store } from 'vuex';

Vue.use(Router)

if(localStorage.getItem('token')){
  store.commit('setToken',localStorage.getItem('token'))
}
if(localStorage.getItem('userInfo')){
  store.commit('setUserInfo',JSON.parse(localStorage.getItem('userInfo')))
}
if(localStorage.getItem('stationId')){
  store.commit('setStationId',localStorage.getItem('stationId'))
}
if(localStorage.getItem('merchantInfo')){
  store.commit('setmerchantId',JSON.parse(localStorage.getItem('merchantInfo')))
}
if(localStorage.getItem('storeId')){
  store.commit('setStore',JSON.parse(localStorage.getItem('storeId')))
}
if(localStorage.getItem('niu')){
  store.commit('setniu',JSON.parse(localStorage.getItem('niu')))
}
if(localStorage.getItem('company')){
  store.commit('setcompany',JSON.parse(localStorage.getItem('company')))
}
if(localStorage.getItem('hash')){
  store.commit('sethash',JSON.parse(localStorage.getItem('hash')))
}
if(localStorage.getItem('order')){
  store.commit('setOrder',JSON.parse(localStorage.getItem('order')))
}
if(localStorage.getItem('good')){
  store.commit('setgood',JSON.parse(localStorage.getItem('good')))
}
if(localStorage.getItem('dealerId')){
  store.commit('setdealerId',JSON.parse(localStorage.getItem('dealerId')))
}
if(localStorage.getItem('sales')){
  store.commit('setsales',JSON.parse(localStorage.getItem('sales')))
}
if(localStorage.getItem('dealerIds')){
  store.commit('setDealerIds',JSON.parse(localStorage.getItem('dealerIds')))
}
if(localStorage.getItem('setStoreSettings')){
  store.commit('setStoreSettingsid',JSON.parse(localStorage.getItem('setStoreSettings')))
}
if(localStorage.getItem('storeName')){
  store.commit('setstoreName',JSON.parse(localStorage.getItem('storeName')))
}

// if(localStorage.getItem('groupId')){
//   store.commit('setGroupId',localStorage.getItem('groupId'))
// }

export default new Router({
  routes: [
    {
      path:'/',
      name:'footeNav',
      component: () => import(/* webpackChunkName: "about" */ './views/footeNav.vue'),
      redirect:'/Home',
      children:[
        {
          path: 'Home',
          meta:{
            // requireAuth:true,
          },
          component: () => import(/* webpackChunkName: "about" */ './views/Home.vue')
        },
        {
          path: 'classify',
          component: () => import(/* webpackChunkName: "about" */ './views/classify.vue')
        },
        {
          path: 'shopping',
          meta:{
            requireAuth:true,
          },
          component: () => import(/* webpackChunkName: "about" */ './views/shopping.vue')
        },
        {
          path: 'my',
          meta:{
            requireAuth:true,
          },
          component: () => import(/* webpackChunkName: "about" */ './views/my.vue')
        },
      ]
    },
    {
      path:'/register',
      name:'register',
      component: () => import(/* webpackChunkName: "about" */ './views/register.vue')
    },
    {
      path:'/lost',
      name:'lost',
      component: () => import(/* webpackChunkName: "about" */ './views/lost.vue')
    },
    {
      path:'/login',
      name:'login',
      component: () => import(/* webpackChunkName: "about" */ './views/login.vue')
    },
    {
      path:'/classify',
      name:'classify',
      component: () => import(/* webpackChunkName: "about" */ './views/classify.vue')
    },
    {
      path:'/shopping',
      name:'shopping',
      component: () => import(/* webpackChunkName: "about" */ './views/shopping.vue')
    },
    
    // {
    //   path:'/my',
    //   name:'my',
    //   component: () => import(/* webpackChunkName: "about" */ './views/my.vue')
    // },
    {
      path:'/confirmOrder',
      name:'confirmOrder',
      component: () => import(/* webpackChunkName: "about" */ './views/shopping-child/confirmOrder.vue')
    },
    {
      path:'/Search',
      name:'Search',
      component: () => import(/* webpackChunkName: "about" */ './views/Search.vue')
    },
    {
      path:'/StoreSettings',
      name:'StoreSettings',
      component: () => import(/* webpackChunkName: "about" */ './views/StoreSettings.vue')
    },
    {
      path:'/StoreSettingsTO',
      name:'StoreSettingsTO',
      component: () => import(/* webpackChunkName: "about" */ './views/StoreSettingsTO.vue')
    },
    {
      path:'/Canvas',
      name:'Canvas',
      component: () => import(/* webpackChunkName: "about" */ './views/Canvas.vue')
    },
    {
      path:'/sousuo',
      name:'sousuo',
      component: () => import(/* webpackChunkName: "about" */ './views/shop/sousuo.vue')
    },
    {
      path:'/shopList',
      name:'shopList',
      component: () => import(/* webpackChunkName: "about" */ './views/shop/shopList.vue')
    },
    {
      path:'/group',
      name:'group',
      component: () => import(/* webpackChunkName: "about" */ './views/group.vue')
    },
    {
      path:'/recruit',
      name:'recruit',
      component: () => import(/* webpackChunkName: "about" */ './views/shop/recruit.vue')
    },
    {
      path:'/activtiy',
      name:'activtiy',
      component: () => import(/* webpackChunkName: "about" */ './views/shop/activtiy.vue')
    },
    {
      path:'/client',
      name:'client',
      component: () => import(/* webpackChunkName: "about" */ './views/client.vue')
    },
    {
      path:'/clientsou',
      name:'clientsou',
      component: () => import(/* webpackChunkName: "about" */ './views/shop/clientsou.vue')
    },
    {
      path:'/Aamion',
      name:'Aamion',
      component: () => import(/* webpackChunkName: "about" */ './Aamion/Aamion.vue')
    },
    {
      path:'/',
      name:'footerNav',
      component: () => import(/* webpackChunkName: "about" */ './components/shop/footerNav.vue'),
      redirect:'shop',
      children:[
        {
          path:'shop',
          component: () => import(/* webpackChunkName: "about" */ './views/shop/shop.vue')
        },
        {
          path:'claify',
          component: () => import(/* webpackChunkName: "about" */ './views/shop/claify.vue')
        },
        {
          path:'brand',
          component: () => import(/* webpackChunkName: "about" */ './views/shop/brand.vue')
        },
        {
          path:'file',
          component: () => import(/* webpackChunkName: "about" */ './views/shop/file.vue')
        },
      ]
    },
    {
      path:'/shoptopallname',
      name:'shoptopallname',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/shoptopallname.vue'),
      redirect:'/shopcollect',
      children:[
        {
          path:'/shopcollect',
          component: () => import(/* webpackChunkName: "about" */ './Mymenu/shopcollect.vue')
        },
        {
          path:'/shoptoshop',
          component: () => import(/* webpackChunkName: "about" */ './Mymenu/shoptoshop.vue')
        },
      ],
    },
    {
      path:'/couponall',
      name:'couponall',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/couponall.vue'),
      children:[
        {
          path:'/coupon',
          component: () => import(/* webpackChunkName: "about" */ './Mymenu/coupon.vue')
        }
      ]
    },
    {
      path:'/shezhiall',
      name:'shezhiall',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/shezhiall.vue'),
      redirect:"/one",
      children:[
        {
          path:'/one',
          component: () => import(/* webpackChunkName: "about" */ './Mymenu/shezhione.vue')
        }
      ]
    },
    {
      path:'/nickname',
      name:'nickname',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/nickname.vue'),
    },
    {
      path:'/changephone',
      name:'changephone',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/changephone.vue'),
    },
    {
      path:'/profile',
      name:'profile',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/profile.vue'),
      redirect:"/profileshoping",
      children:[
        {
          path:'/profileshoping',
          component: () => import(/* webpackChunkName: "about" */ './Mymenu/profileshoping.vue')
        },
        {
          path:'/storesdata',
          component: () => import(/* webpackChunkName: "about" */ './Mymenu/storesdata.vue')
        }
      ]
    },
    {
      path:'/changepassword',
      name:'changepassword',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/changepassword.vue'),
    },
    {
      path:'/thenewstore',
      name:'thenewstore',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/thenewstore.vue'),
    },
    {
      path:'/thejumpinnew',
      name:'thejumpinnew',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/thejumpinnew.vue'),
    },
    {
      path:'/changenewshopping',
      name:'changenewshopping',
      component: () => import(/* webpackChunkName: "about" */ './Mymenu/changenewshopping.vue'),
    },
    { 
      path:'/details',
      name:'details',
      component: () => import(/* webpackChunkName: "about" */ './views/details.vue')
    },
    {
      path:'/detailedList',
      name:'detailedList',
      component: () => import(/* webpackChunkName: "about" */ './views/shopping-child/detailedList.vue')
    },
    {
      path:'/shops',
      name:'shops',
      component: () => import(/* webpackChunkName: "shops" */ './views/Order/shops.vue')
   },
    {
      path:'/Supplier',
      name:'Supplier',
      component: () => import(/* webpackChunkName: "Supplier" */ './views/Order/Supplier.vue')
    },
    {
      path:'/shopLists',
      name:'shopLists',
      component: () => import(/* webpackChunkName: "shopLists" */ './views/Order/shopLists.vue')
    },
    {
      path:'/Securities',
      name:'Securities',
      component: () => import(/* webpackChunkName: "Securities" */ './views/Order/Securities.vue')
    },
    {
      path:'/orders',
      name:'orders',
      component: () => import(/* webpackChunkName: "orders" */ './views/Order/orders.vue')
    },
    {
      path:'/orderss',
      name:'orderss',
      component: () => import(/* webpackChunkName: "orderss" */ './views/Order/orderss.vue')
    },
    {
      path:'/sales',
      name:'sales',
      component: () => import(/* webpackChunkName: "sales" */ './views/Order/sales.vue')
    },
    {
      path:'/staff',
      name:'staff',
      component: () => import(/* webpackChunkName: "staff" */ './views/Order/staff.vue')
    },
    {
      path:'/staffs',
      name:'staffs',
      component: () => import(/* webpackChunkName: "staffs" */ './views/Order/staffs.vue')
    },
    {
      path:'/employees',
      name:'employees',
      component: () => import(/* webpackChunkName: "employees" */ './views/Order/employees.vue')
    },
    {
      path:'/bill',
      name:'bill',
      component: () => import(/* webpackChunkName: "sales" */ './views/Order/sales-child/bill.vue')
    },
    {
      path:'/management',
      name:'management',
      component: () => import(/* webpackChunkName: "orderss" */ './Mymenu/shopgo/management.vue')
    },
    {
      path:'/fenye',
      name:'fenye',
      component: () => import(/* webpackChunkName: "orderss" */ './Mymenu/shopgo/fenye.vue')
    },
    {
      path:'/fenyetwo',
      name:'fenyetwo',
      component: () => import(/* webpackChunkName: "orderss" */ './Mymenu/shopgo/fenyetwo.vue')
    },
    {
      path:'/fenyeone',
      name:'fenyeone',
      component: () => import(/* webpackChunkName: "orderss" */ './Mymenu/shopgo/fenyeone.vue')
    },
    {
      path:'/fenyethrss',
      name:'fenyethrss',
      component: () => import(/* webpackChunkName: "orderss" */ './Mymenu/shopgo/fenyethrss.vue')
    },
    {
      path:'/tubeall',
      name:'tubeall',
      component: () => import(/* webpackChunkName: "orderss" */ './Mymenu/goodsinthetube/tubeall.vue'),
      redirect:"/commodity",
      children:[
        {
          path:'/commodity',
          component: () => import(/* webpackChunkName: "orderss" */ './Mymenu/goodsinthetube/commodity.vue')
        },
        {
          path:'/supply',
          component: () => import(/* webpackChunkName: "orderss" */ './Mymenu/goodsinthetube/supply.vue')
        }
      ]
    },
  ],
})
router.beforeEach((to,from,next)=>{
  if(to.meta.requireAuth){
    if(store.state.token){
      next();
    }else{
      next({
        path:'/login',
        query:{redirect:to.fullPath}
      })
    }
  }else{
    next()
  }
})
